import json
from streamlit_folium import folium_static
import folium
import branca.colormap as cm
import streamlit as st
import pandas as pd
print("\x1b[1;92mStreamlit script running...\x1b[0m")
st.title("Germany vs. Denmark Euro 2024 DTN Lightning API")
st.text(
"The game between Germany and Denmark and Euro 2024 "
"had to be paused due to a thunderstorm."
)
st.text(
"We can see how close the lightning was using DTN's Lightning API"
)
st.text(
"https://devportal.dtn.com/catalog/Weather/dtn-lightning-api"
)
st.text(
"Here is a sample of the data"
)
df = pd.read_pickle("germany_vs_denmark_euro2024_DTNlightningAPI.pkl")
st.dataframe(df.head())
st.text(
"Here is an image of the lightning from the stadium. "
"If they image doesn't. render see https://www.reddit.com/r/pics/comments/1drjhr9/lightning_strike_captured_during_germany_vs/#lightbox"
)
st.image("img.jpeg")
st.text(
"The plot shows lightning strikes within 10 km of the statdium"
)
import json
with open('germany_vs_denmark_euro2024_DTNlightningAPI.geojson', 'r') as file:
data = json.load(file)
m = folium.Map(location=[51.4925888, 7.4518574], zoom_start=11)
colormap = cm.LinearColormap(
colors=["#0d0887", "#7e03a8", "#cc4778", "#f89540", "#f0f921"],
vmin=0,
vmax=3,
)
m.add_child(colormap)
for feature in data['features']:
properties = feature['properties']
coordinates = feature['geometry']['coordinates']
folium.CircleMarker(
location=[coordinates[1], coordinates[0]], # [latitude, longitude]
radius=10, # Fixed radius of 10
popup=folium.Popup(
f"Category: {properties['15_min_category_from_kick_off']}<br>"
f"UTC Time: {properties['utc_time']}<br>"
f"Local Time: {properties['local_time']}"
),
color=colormap(properties["15_min_category_from_kick_off"]),
fill=True,
fillColor=colormap(properties["15_min_category_from_kick_off"]),
fillOpacity=0.7,
stroke=True,
weight=2,
).add_to(m)
# Add the black circle
folium.CircleMarker(
location=[51.4925888, 7.4518574],
radius=20,
color="black",
fill=True,
fillColor="black",
fillOpacity=0.7,
stroke=True,
weight=2,
).add_to(m)
#m = folium.LayerControl().add_to(m)
folium_static(m, width=1000)
st.markdown(
"""
### Useful links:
* [Streamlit official website](https://streamlit.io/)
* [Streamlit documentation](https://docs.streamlit.io/)
### Alternatives
Also take a look at [stlite](https://edit.share.stlite.net/), a similar platform that allows you to create, run, edit, and share Python applications directly in your browser.
Py.cafe runs an unmodified version of streamlit, compared to stlite which has some modifications to make it work in the browser.
### Community
* [Py.cafe Discord](https://discord.gg/RpwWnFV3Dv)
* [Streamlit community forum](https://discuss.streamlit.io/)
"""
)